var app = getApp();
Page({
  data: {
    courselist: null,
    sid: null,
  },
  onLoad: function (options) {
    var that = this;
    if (app.globalData.isStudent) {
      that.setData({
        sid: app.globalData.sId
      })
    }
    getCourses(that, this.data.sid);
  },

  onShow: function () {
    var that = this;
    if (app.globalData.isStudent) {
      that.setData({
        sid: app.globalData.sId
      })
    }
    getCourses(that, this.data.sid);
  },

  onPullDownRefresh: function () {
    //上拉刷新再次联网取数据
    var that = this;
    getCourses(that, this.data.sid);
  },

})
function getCourses(that, sid) {
  console.log(that)
  wx.request({
    url: `https://geek-team.xin/course/findBySid`,
    method: 'POST',
    header: {
      'content-type': 'application/x-www-form-urlencoded'
    },
    data: {
      sId: sid
    },
    success(res) {
      if (res.data != []) {
        that.setData({
          courselist: res.data
        })
        console.log(res.data)
      }
    },
    fail: (e) => console.log(e)
  })
}